<template>
  <div>
    <p class="title">推荐歌单</p>
    <van-row gutter="2" type="flex" justify="space-between">
      <van-col
        span="8"
        @click="gorecomDetail(recommendSong, index)"
        v-for="(recommendSong, index) in recommendSongs"
        :key="index"
      >
        <img
          class="msgImg"
          :src="recommendSong.picUrl"
          :title="recommendSong.copywriter"
        />
        <div class="listen">
          <van-icon name="service-o" />
          <span>{{ (recommendSong.playCount / 10000).toFixed(1) + "万" }}</span>
        </div>
        <p class="msgTitle">{{ recommendSong.name }}</p>
      </van-col>
    </van-row>

    <p class="title">最新音乐</p>
    <song-item :newSongs="newSongs"></song-item>
    <div class="logo">
      <div>
        <img src="../../assets/logo.png" alt="" />
        <span>网易云音乐</span>
      </div>
      <div @click="$router.push({name:'GoDownLoad'})">打开APP，发现更多好音乐 ></div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState({
      recommendSongs: (state) => state.Home.recommendSongs,
      newSongs: (state) => state.Home.newSongs,
    }),
  },
  mounted() {
    this.$store.dispatch("getRecommendSongs", 6);
    this.$store.dispatch("getNewSongs", 10);
  },
  methods: {
    gorecomDetail(recommendSong, index) {
      sessionStorage.setItem("recommendSong", JSON.stringify(recommendSong));
      this.$router.push({
        name: "RecomdDetail",
        query: { id: recommendSong.id },
      });
    },
  },
};
</script>

<style scoped lang="less">
.title {
  padding: 0.2666667rem 0.24rem;
  margin: 0.1rem 0rem 0.1rem 0;
  background-color: #eee;
  color: #333;
  font-size: 0.4rem;
  border-left: 3px solid red;
}
.van-col {
  text-align: center;
  margin: 0.1667rem 0px;
  position: relative;
}
.msgImg {
  width: 100%;
  height: auto;
}
.msgTitle {
  display: inline-block;
  height: 2.5em;
  font-size: 0.3467rem;
  padding: 0.05rem 0.5em 0 0.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 1;
}
.listen {
  background-color: rgb(176, 163, 163);
  box-shadow: 0.0667rem 0.0667rem 0.333rem rgb(176, 163, 163);
  z-index: 10;
  position: absolute;
  right: 0.1666667rem;
  top: 0.1667rem;
  font-size: 0.2667rem;
  color: #fff;
}

.logo {
  width: 100%;
  height: 5.3333rem;
  background-image: url(https://s3.music.126.net/mobile-new/img/recommand_bg_2x.png?d045fafc60e017b653f8065a87496922=);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  div:nth-child(1) {
    text-align: center;
    margin-top: 1.3333rem;
    font-size: .9333rem;
    img {
      width: 1.1467rem;
      height: 1.1467rem;
      vertical-align: middle;
      margin: .2667rem;
    }
  }
  div:nth-child(2){
    text-align: center;
    margin: 0rem auto;
    border: 1px solid #D33A31;
    line-height: 1.0667rem;
    color: #D33A31;
    border-radius: .5333rem;
    width: 8.0267rem;
    height: 1.0667rem;
    font-size: .4267rem;
  }
}
</style>